package com.ck.ckcloud.networkmanagement.infrastructure.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ck.ckcloud.common.core.util.R;
import com.ck.ckcloud.networkmanagement.domain.entity.Resource;
import com.ck.ckcloud.networkmanagement.facade.NetworkManagementFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 资源控制器
 *	作为基础设施对外暴露REST协议的服务
 * @author Aiden <a href="mailto:adam602260@gmail.com"/>
 * @version TestResource.java v0.1
 * @create 2019-09-17 22:39
 */
@RestController
@RequestMapping("/resource")
public class ResourceController {

	/**
	 * 网管门户应用层
	 */
	@Autowired
	private NetworkManagementFacade networkManagementFacade;

	/**
	 * 根据uniqueId查询一个资源
	 * @param uniqueId
	 * @return
	 */
	@GetMapping("/{uniqueId}")
	public R getResourceByUniqueId(@PathVariable String uniqueId){
		Resource resource = networkManagementFacade.getResourceById(uniqueId);
		if (resource == null){
			throw new RuntimeException("resource is null");
		}

		return new R<>(resource);
	}

	/**
	 * 分页查询资源信息
	 * @param page
	 * @return
	 */
	@GetMapping("/page")
	public R listResoureByPage(Page page){
		IPage iPage = networkManagementFacade.listResourceByPage(page);

		return new R<>(iPage);
	}

}
